
#ifndef __MYMATH_H_
#define __MYMATH_H_

#include <string>
#include <map>

struct Voxel
{
  int a;
  int b;
  int c;

};
//id = x + a * y + b * a * z;

__inline void IDTOXYZ(long long id, Voxel& vox, int& ox, int& oy, int& oz)
{
  ox = id % vox.a;
  oy = ((id - ox) / vox.a) % vox.b;
  oz = (id - ox - oy * vox.a) / (vox.a * vox.b);
}
__inline void XYZTOID(Voxel& vox, int& ix, int& iy, int& iz, long long& oid)
{
  oid = ix + iy * vox.a + iz * vox.b * vox.a;
}

__inline void IDTOXYZ2(long long id, Voxel& vox, int& ox, int& oy, int& oz)
{
  ox = id % vox.b;
  oy = ((id - ox) / vox.b) % vox.b;
  oz = (id - ox - oy * vox.b) / vox.c;
}
__inline void XYZTOID2(Voxel& vox, int& ix, int& iy, int& iz, long long& oid)
{
  oid = ix + iy * vox.b + iz * vox.c;
}


typedef std::map<std::string, void*> MAPFIELD_ATT;

#define InvalidValue (-1e10)

class GridAttributeStore
{
public:
  GridAttributeStore(Voxel& vox) :mVox(vox){}
  ~GridAttributeStore();
  void SetField(std::string field, size_t gridid, double value);
  double GetValue(std::string field, size_t gridid);
  double GetValue(std::string field, int  x,int y,int z);

  void Reset();

  MAPFIELD_ATT mStore;
  Voxel mVox;
};


#endif  // !1
